<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="5" :md="6" :sm="24">
            <a-form-item label="参数名称">
              <a-input placeholder="请输入参数名称" v-model="queryParam.name"></a-input>
            </a-form-item>

          </a-col>
          <a-col :xl="4" :lg="5" :md="6" :sm="24">
            <a-form-item label="参数Code">
              <a-input placeholder="请输入参数Code" v-model="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
            <a-col :xl="3" :lg="4" :md="5" :sm="24">
              <a-form-item label="参数类型">
                <j-dict-select-tag placeholder="请选择参数类型" v-model="queryParam.type" dictCode="sys_config_type"/>
              </a-form-item>
            </a-col>

         <!-- <a-col :xl="3" :lg="4" :md="5" :sm="24">
            <a-form-item label="系统参数">
              <j-dict-select-tag placeholder="请选择参数类型" v-model="queryParam.sysParam" dictCode="yn"/>
            </a-form-item>
          </a-col>-->
            <a-col :xl="4" :lg="5" :md="6" :sm="24">
              <a-form-item label="参数数据值">
                <a-input placeholder="请输入参数数据值" v-model="queryParam.value"></a-input>
              </a-form-item>
            </a-col>

          <a-col :xl="5" :lg="6" :md="7" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
             <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END flase -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" v-has="'sys:config:add'" type="primary" icon="plus">新增</a-button>
      <!--<a-button type="primary" icon="download" @click="handleExportXls('系统参数配置表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>-->
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay"  v-has="'sys:config:delete'">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="valueSlot" slot-scope="text,record">
          <j-text-slot v-if="record.type=='input' || record.type=='textarea' || record.type=='editor' "  v-model="text" ></j-text-slot>
          <j-file-slot v-else v-model="text"></j-file-slot>
        </template>


        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'sys:config:edit'">编辑</a>

          <a-divider type="vertical"  v-has="'sys:config:edit'"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item  v-has="'sys:config:delete'">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <j-image-open ref="previewImageOpen"></j-image-open>
    <sys-config-modal ref="modalForm" @ok="modalFormOk"></sys-config-modal>

  </a-card>
</template>

<script>
  const doc = require('@/assets/fileImage/doc.png')
  const pdf = require('@/assets/fileImage/pdf.png')
  const ppt = require('@/assets/fileImage/ppt.png')
  const txt = require('@/assets/fileImage/txt.png')
  const zip = require('@/assets/fileImage/zip.png')
  const xls = require('@/assets/fileImage/xls.png')

  import { httpAction, getAction } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import SysConfigModal from './modules/SysConfigModal'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'SysConfigList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      SysConfigModal,
      JEllipsis
    },
    data () {
      return {
        doc,
        pdf,
        ppt,
        txt,
        zip,
        xls,
        description: '系统参数配置表管理页面',
        // 表头
        columns: [
          {
            title:'位置',
            align:"center",
            dataIndex: 'position'
          },
          {
            title:'参数名称',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'参数Code',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'参数类型',
            align:"center",
            dataIndex: 'type_dictText'
          },
          {
            title:'参数数据值',
            align:"center",
            dataIndex: 'value',
            scopedSlots: { customRender: 'valueSlot' }
          },

          /*{
            title:'系统参数',
            align:"center",
            dataIndex: 'sysParam_dictText'
          },*/
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/sys/config/list",
          delete: "/sys/config/delete",
          deleteBatch: "/sys/config/deleteBatch",
          exportXlsUrl: "/sys/config/exportXls",
          importExcelUrl: "/sys/config/importExcel",
        },
        dictOptions:{},
        superFieldList:[],
        isorter: {
          column: "position",
          order: "asc"
        },
        queryParam: {
          isHide:'0'
        },
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      searchReset(){
        this.queryParam = {isHide:'0'}
        this.loadData(1);
      },

      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'name',text:'参数名称',dictCode:''})
        fieldList.push({type:'string',value:'code',text:'参数Code',dictCode:''})
        fieldList.push({type:'string',value:'type',text:'参数类型',dictCode:'sys_config_type'})
        fieldList.push({type:'Text',value:'value',text:'参数数据值',dictCode:''})
        fieldList.push({type:'int',value:'position',text:'位置',dictCode:''})
        fieldList.push({type:'string',value:'isHide',text:'是否 隐藏 0 否 1 是',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>